package com.mju.config;

import com.alipay.api.*;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

// 支付宝沙箱支付配置类
@Component
public class AlipayClientConfig {

  // 内网穿透URL 隧道id 110630403881
  public static String ngrokUrl = "http://sunny.v5.idcfengye.com";
  // 支付宝网关地址
  public static String gatewayUrl = "https://openapi-sandbox.dl.alipaydev.com/gateway.do";
  // appId
  public static String appId = "9021000122683695";
  // sellerId
  public static String sellerId = "2088721003893546";
  // 应用私钥
  public static String appPrivateKey =
      "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC9ElXYyhmGAVHj5FsB/IUv4by/EssYpoxbYNFOwRfJPHuPEuLYErRh6LW2vWo1GEMoNEOk/54Kwm9RQzYgkseYL8Y8PNn2Jbo7hxzMm9+Ffg+iQS/WtlIMAPx10XRIVILK+A18R7mViqLNmB7cPe+p0249vaUj7f7+sAEQUScYSjTPW90T369M5tuo0RcqJNbVjEqFq/C0r/R1tfIX3vL7qGxvHDLfudKqa3DLgjjqI29WwqrDV7Pio/jUVbANuexjzl0aSA/rPHFA5A0ZXNG0SV36DNiopIrPPS+NNL+ZKtV5YbwgNj+3gXbkGyed6mqJOImMxC3dqmOA3qKFHhC9AgMBAAECggEAWmugXpMYbbvH3ALjeym20FVWnNJyCpHr4e+FafJyW6zvMldH4Sng1koiTQh8+HNn+pw0FX6hqGegMO7BvgY0KhX+6eP4IP2d+MX/AeMxnHfTJjeilz6OMmtuUTIgOE8iVcsXN+5dVKT+gvBTIeUE7uTMff5qMaqqHkcx2wnUdoqCe71a7ynxDgQdjjAoRjrvXY5qRwUcChKzfWFXol09Y485rBvsuLlqK/D2DH3cXAMUlhvKRC+Wv3jkjMfLPgvkioXk9BswxdhLyh8Vt5tsXuGWpcSbgXU0MRoFjolZp0c7ST/Y0//R7lEESfT2wN+Prn0r+U/7W7jtuwjRfDExQQKBgQD41WnZDUB+W7mopcfxswi7TK0vS9x6nAJ+WevMxe5TY4KJ5AaYQluYailODQh0WHdkJLi/Ge7KqSRRY2+JJ1/g7gtcaPthU2aA1MHaiSDZcASAf3AAEjFeAGFNecRblTGMAUnkYsqY+Caruyn/etDcyu10lmoJKSyhafn5m+vwmQKBgQDChE/TzEulxt+TFLJ7B5MeMYJFT820aIFPGQWmMkpG4kJMolVr6+CY24WaZIfoZQwDJgMv5aQ4FfA1Ui9JoZnZF890dxPCsbP60zCO3zmzBCrQL9EPwOawaFlvfcdDc/L+ONTMroiASqjXc/I+2GjTypIn17kAIaEMViABAJEjxQKBgQCcxoFRAptuwUXhLsohy0YmE/JNiUNZcK/VgbwiIVa97UVSsXtCNRTWm5R4m5eHDjHyw3wu0xzzTMwYB0k/pbIv2msIBxDSyiQb6XBVyu4KcRw1BZXARbYa3qxvjtebSA2Wgz1WCrRQ2pAqxNp6H5w2cBhZy2b1bJ60+DtJ++YUiQKBgCOPZryUk5vJ4KOV3A8r0lRpvqQHM9bwZ/ta2rKIbRXKVU6HOtCQ/a1ULHeOO15b4rdMoraF5+Cs+g31aVmvpl2OwclL35vvOrT3GOB1pKm6cE1BAJo9rK7BVOBSATSupNSe9SA6JBA4FefVdYrRq1BUryWDhXmlrDiCIjWssdv1AoGABu+6Q3buuCXXQMZ60vXTztYZrhFzlIQ2cqCc6UMf0aLr6jm1BYMobf7U4TNwyd8I83QDdfi1licCqtehrCUNAWPiG1/dRUe2mDsKPp+wSqGMJQn5w0qE3QR5RWH6QTaUNdaSE81aJk1RQ8xPnJ3U2hh6rdIlAPmeslPibFGI3tI=";
  // 发送数据的格式 目前只能为json
  public static String format = "json";
  // 设置字符集编码 目前只能为utf-8
  public static String charset = "utf-8";
  // 支付宝公钥
  public static String alipayPublicKey =
      "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApbmjJBL3eJykppp/oU8ymTjLMy9W27Tei9P1n2kdbkkNWtoC/ulskQSURxjBPxX6Li1WUK+XlgykIYQvVwTtbB2JJWZjTk41U2ruqyQSxu9dOYuDmhRQOdjSqXWAz6A5L7Pn8trZDuASgVTanFCWdiMfiMdLRmNsMsGzwmth8DB29NDpVDSPhjFFqb6LE6FFg4kEi/E8Gw9lG619sgugim56KvirAn4lpPPGCEUip3Bvt/+dCsf/6iMX6Zetajri7JhKykr6zIQ9Rs++oPPMpDWpgolxd7nRi+lEKSK8eS8mC54Lset1qw8j36Pn4a6LO5uuJIMY+8WSS2wPpO42yQIDAQAB";
  // 支付宝签名 目前是 RSA2
  public static String signType = "RSA2";
  // content模式
  public static String content =
          "-----BEGIN CERTIFICATE-----\r\nMIIBszCCAVegAwIBAgIIaeL+wBcKxnswDAYIKoEcz1UBg3UFADAuMQswCQYDVQQG\r\nEwJDTjEOMAwGA1UECgwFTlJDQUMxDzANBgNVBAMMBlJPT1RDQTAeFw0xMjA3MTQw\r\nMzExNTlaFw00MjA3MDcwMzExNTlaMC4xCzAJBgNVBAYTAkNOMQ4wDAYDVQQKDAVO\r\nUkNBQzEPMA0GA1UEAwwGUk9PVENBMFkwEwYHKoZIzj0CAQYIKoEcz1UBgi0DQgAE\r\nMPCca6pmgcchsTf2UnBeL9rtp4nw+itk1Kzrmbnqo05lUwkwlWK+4OIrtFdAqnRT\r\nV7Q9v1htkv42TsIutzd126NdMFswHwYDVR0jBBgwFoAUTDKxl9kzG8SmBcHG5Yti\r\nW/CXdlgwDAYDVR0TBAUwAwEB/zALBgNVHQ8EBAMCAQYwHQYDVR0OBBYEFEwysZfZ\r\nMxvEpgXBxuWLYlvwl3ZYMAwGCCqBHM9VAYN1BQADSAAwRQIgG1bSLeOXp3oB8H7b\r\n53W+CKOPl2PknmWEq/lMhtn25HkCIQDaHDgWxWFtnCrBjH16/W3Ezn7/U/Vjo5xI\r\npDoiVhsLwg==\r\n-----END CERTIFICATE-----\r\n\r\n-----BEGIN CERTIFICATE-----\r\nMIIF0zCCA7ugAwIBAgIIH8+hjWpIDREwDQYJKoZIhvcNAQELBQAwejELMAkGA1UE\r\nBhMCQ04xFjAUBgNVBAoMDUF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ILKuqUYSHc2GPYiHVflDh5nDymCMOQFcFG3WsEuB+EYQPFgIU\r\n1DHmdZcz7Llx8UOZXX2JupWCYzK1XhJb+r4hK5ncf/w8qGtYlmyJpxk3hr1TfUJX\r\nYf4Zr0fJsGuv\r\n-----END CERTIFICATE-----";

  // 订单异步回调地址
  public static String notifyUrl = ngrokUrl + "/alipay/notifyNotice";
  // 订单同步回调地址
  public static String returnUrl = "http://localhost:10010/alipay/returnNotice";

  // 移动端订单异步回调地址
  public static String notifyUrlForMobileTerminal = ngrokUrl + "/alipay/notifyUrlForMobileTerminal";
  // 移动端订单同步回调地址
  public static String returnUrlForMobileTerminal = "http://localhost:10010/alipay/returnNoticeForMobileTerminal";

  // 购买会员的异步回调地址
  public static String notifyUrlForVip = ngrokUrl + "/alipay/notifyUrlForVip";
  // 购买会员的同步回调地址
  public static String returnUrlForVip = "http://localhost:10010/alipay/returnNoticeForVip";


  @Bean
  public AlipayClient alipayClient() throws AlipayApiException {
    AlipayConfig alipayConfig = new AlipayConfig();
    // 设置appId
    alipayConfig.setAppId(appId);
    // 设置私钥
    alipayConfig.setPrivateKey(appPrivateKey);
    // 设置支付宝公钥
    alipayConfig.setAlipayPublicKey(alipayPublicKey);
    // 设置支付宝网关
    alipayConfig.setServerUrl(gatewayUrl);
    // 设置请求格式,固定值json.
    alipayConfig.setFormat(AlipayConstants.FORMAT_JSON);
    // 设置字符集
    alipayConfig.setCharset(AlipayConstants.CHARSET_UTF8);
    // 设置签名类型
    alipayConfig.setSignType(AlipayConstants.SIGN_TYPE_RSA2);
    // 设置content的模式
    alipayConfig.setRootCertContent(content);
    // 构造alipayClient
    return new DefaultAlipayClient(alipayConfig);
  }
}
